package com.feiyu.auth.granter;

import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author tang ming
 * @since 2021/12/5 22:24
 */
public class TokenGranterBuilder {

    private static final Map<String, TokenGranter> GRANTER_POOL = new ConcurrentHashMap<>();

    static {
        GRANTER_POOL.put(PasswordTokenGranter.GRANT_TYPE, SpringUtil.getBean(PasswordTokenGranter.class));
        GRANTER_POOL.put(CaptchaTokenGranter.GRANT_TYPE, SpringUtil.getBean(CaptchaTokenGranter.class));
    }

    /**
     * 策略模式获取granter
     * */
    public static TokenGranter get(String grantType){
        return GRANTER_POOL.get(Func.toStr(grantType,PasswordTokenGranter.GRANT_TYPE));
    }
}
